﻿using System;

namespace Jayden.Dll.Core
{
	public class MaybeDisposable<T> : IDisposable where T: IDisposable
	{
		private bool m_ShouldDispose = true;
		private T m_Disposable;

		public MaybeDisposable(T disposable, bool shouldDispose = true)
		{
			m_ShouldDispose = shouldDispose;
			m_Disposable = disposable;
		}

		public bool ShouldDispose { get { return m_ShouldDispose; } }
		public T Disposable { get { return m_Disposable; } }


		public void Dispose()
		{
			if (ShouldDispose)
				m_Disposable.Dispose();
			m_ShouldDispose = false;
			m_Disposable = default(T);
		}
	}
}
